#!/usr/bin/python
# -*- coding: UTF-8 -*-
import pymongo
from config import *
client=pymongo.MongoClient(MONGO_URL);
import pandas as pd
import numpy as np
from config import *
import pyecharts as pc
import matplotlib.pyplot as plot
import tushare
import jieba
import re
db=client["taobao"]
plot.style.use('ggplot')
plot.rcParams['font.sans-serif'] = ['SimHei']
plot.rcParams['font.family']='sans-serif'
"https://blog.csdn.net/stevenkwong/article/details/52528616"







def get_data():
    queryArgs = {}
    projectionFields = {'_id': False}  # 用字典指定
    result = db["飞利浦电吹风"].find(queryArgs,projectionFields)

    return result

def filter_price(str):
    price=np.NAN
    res=re.compile("\d+").search(str)
    if res:
        price=res.group(0)
    return price

'''          deal      price                         allsalse

mean      187.357402    74.266576  1.096542e+04     48291696

mean      36.692395   149.730136  5.850539e+03      20617299

'''


def main():
    data=pd.DataFrame(list(get_data()))
    # data=data[data["title"].str.contains("电吹风")]
    data["price"]=data["price"].apply(filter_price)
    data["price"]=data["price"].astype(np.int32)
    data["deal"] = data["deal"].astype(np.int32)
    # data["sales"]=data["price"]*data["deal"]
    data=data.sort_values(by="deal",ascending=False)

    # print(data["sales"].sum())
    print(data.iloc[0])

    # print(data.describe())
    # print(data.head())



if __name__ == '__main__':
    main()